home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / Normal.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  2KB  |  68 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _Normal_h
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #pragma cplusplus
  22. #endif
  23. #define _Normal_h 
  24.  
  25. #include <Random.h>
  26.  
  27. class Normal: public Random {
  28.     char haveCachedNormal;
  29.     double cachedNormal;
  30.  
  31. protected:
  32.     double pMean;
  33.     double pVariance;
  34.     double pStdDev;
  35.     
  36. public:
  37.     Normal(double xmean, double xvariance, RNG *gen);
  38.     double mean();
  39.     double mean(double x);
  40.     double variance();
  41.     double variance(double x);
  42.     virtual double operator()();
  43. };
  44.  
  45.  
  46. inline Normal::Normal(double xmean, double xvariance, RNG *gen)
  47. : Random(gen) {
  48.   pMean = xmean;
  49.   pVariance = xvariance;
  50.   pStdDev = sqrt(pVariance);
  51.   haveCachedNormal = 0;
  52. }
  53.  
  54. inline double Normal::mean() { return pMean; };
  55. inline double Normal::mean(double x) {
  56.   double t=pMean; pMean = x;
  57.   return t;
  58. }
  59.  
  60. inline double Normal::variance() { return pVariance; }
  61. inline double Normal::variance(double x) {
  62.   double t=pVariance; pVariance = x;
  63.   pStdDev = sqrt(pVariance);
  64.   return t;
  65. };
  66.  
  67. #endif
  68.